<?php
class CPage {
	
	static public function divPages($pageNumber, $page, $thisfile) {
		if ($pageNumber > 0) {
			$pre = $page - 1;
			$next = $page + 1;
			$ye=0;
			$loop='';
			$firstAndLast='';
			$nextAndLast='';
			
			if(strpos($thisfile,'?')){
				
				$thisfile=$thisfile.'&';
				
			}else{
				
				$thisfile=$thisfile.'?';
				
			}
			if ($page > 6) {
				if ($page + 1 <= $pageNumber) {
					if($pageNumber-$page>2){									
						$ye = $page - 7+3;	
					}else{
						$ye = $page - 7 + 1;
					}
				} else {
					$ye = $page - 7;
				}
			}
			if ($pre > 0) {
				
				$firstAndLast = "<a class='pageStyle' href='" . $thisfile . "page=1' title='First'>&lt;&lt;</a> 
				<a class='pageStyle' href='" . $thisfile . "page=" . $pre . "' title='Prev'>&lt;</a>";
			
			}
			for($i = $ye; $i < $ye + 7; $i ++) {
				if ($page == ($i + 1)) {
					$loop .= "<a class='current' id='current' href='" . $thisfile . "page=" . ($i + 1) . "'>" . ($i + 1) . "</a> ";
				} else {
					$loop .= "<a class='pageStyle' href='" . $thisfile . "page=" . ($i + 1) . "'>" . ($i + 1) . "</a> ";
				}
				if ($i == ($pageNumber - 1)) {
					break;
				}
			}
			
			if ($next <= $pageNumber) {
				
				$nextAndLast = "<a class='pageStyle' href='" . $thisfile . "page=" . $next . "' title='Next'>&gt;</a> 
				<a class='pageStyle' href='" . $thisfile . "page=" . $pageNumber . "' title='Last'>&gt;&gt;</a>";
			
			}
			return $firstAndLast . ' ' . $loop . ' ' . $nextAndLast;
		} else {
			return "";
		}
	}
	
	static public function categoryDivPages($pageNumber, $page, $thisfile, $productName, $subfix = '') {
		if ($subfix) {
			$productName = $productName . '-' . $subfix;
		}
		if ($pageNumber > 0) {
			$pre = $page - 1;
			$next = $page + 1;
			$ye=0;
			$loop='';
			$firstAndLast='';
			$nextAndLast='';			
			
			if ($page > 6) {
				if ($page + 1 <= $pageNumber) {
					if($pageNumber-$page>2){									
						$ye = $page - 7+3;	
					}else{
						$ye = $page - 7 + 1;
					}
				} else {
					$ye = $page - 7;
				}
			}
			if ($pre > 0) {
				
				$firstAndLast = "<a class='pageStyle' href='" . $thisfile . "-1-" . $productName . ".html' title='First'>&lt;&lt;</a> 
				<a class='pageStyle' href='" . $thisfile . "-" . $pre . "-" . $productName . ".html' title='Prev'>&lt;</a>";
			
			}
			for($i = $ye; $i < $ye + 7; $i ++) {
				if ($page == ($i + 1)) {
					$loop .= "<a class='current' id='current' href='" . $thisfile . "-" . ($i + 1) . "-" . $productName . ".html'>" . ($i + 1) . "</a> ";
				} else {
					$loop .= "<a class='pageStyle' href='" . $thisfile . "-" . ($i + 1) . "-" . $productName . ".html'>" . ($i + 1) . "</a> ";
				}
				if ($i == ($pageNumber - 1)) {
					break;
				}
			}
			
			if ($next <= $pageNumber) {
				
				$nextAndLast = "<a class='pageStyle' href='" . $thisfile . "-" . $next . "-" . $productName . ".html' title='Next'>&gt;</a> 
				<a class='pageStyle' href='" . $thisfile . "-" . $pageNumber . "-" . $productName . ".html' title='Last'>&gt;&gt;</a>";
			
			}
			return $firstAndLast . ' ' . $loop . ' ' . $nextAndLast;
		} else {
			return "";
		}
	}
	
	static public function divPagesAdmin($pageNumber, $page, $thisfile) {
		if ($pageNumber > 0) {
			$pre = $page - 1;
			$next = $page + 1;
			$ye=0;
			$loop='';
			$firstAndLast='';
			$nextAndLast='';
			
			if(strpos($thisfile,'?')){
				
				$thisfile=$thisfile.'&';
				
			}else{
				
				$thisfile=$thisfile.'?';
				
			}
			if ($page > 6) {
				if ($page + 1 <= $pageNumber) {
					if($pageNumber-$page>2){									
						$ye = $page - 7+3;	
					}else{
						$ye = $page - 7 + 1;
					}
				} else {
					$ye = $page - 7;
				}
			}
			if ($pre > 0) {
				
				$firstAndLast = "<a class='pageStyle' href='" . $thisfile . "page=1' title='First'>&lt;&lt;</a> 
				<a class='pageStyle' href='" . $thisfile . "page=" . $pre . "' title='Prev'>&lt;</a>";
			
			}
			for($i = $ye; $i < $ye + 7; $i ++) {
				if ($page == ($i + 1)) {
					$loop .= "<a class='current' id='current' href='" . $thisfile . "page=" . ($i + 1) . "'>" . ($i + 1) . "</a> ";
				} else {
					$loop .= "<a class='pageStyle' href='" . $thisfile . "page=" . ($i + 1) . "'>" . ($i + 1) . "</a> ";
				}
				if ($i == ($pageNumber - 1)) {
					break;
				}
			}
			
			if ($next <= $pageNumber) {
				
				$nextAndLast = "<a class='pageStyle' href='" . $thisfile . "page=" . $next . "' title='Next'>&gt;</a> 
				<a class='pageStyle' href='" . $thisfile . "page=" . $pageNumber . "' title='Last'>&gt;&gt;</a>";
			
			}
			
			for($i = 1; $i <= $pageNumber; $i ++) {
				if ($page == ($i)) {
					$loops .= "<option value=\"$i\" selected=\"selected\">$i</option>";
				} else {
					$loops .= "<option value=\"$i\">$i</option>";
				}
			}

            if($loops) $loops="<span><select name=\"page\" onchange=\"GGSHOP.url.redirect('$thisfile', $(this).val())\">".$loops."</select></span>";
			
			return $firstAndLast . ' ' . $loop . ' ' . $nextAndLast . '&nbsp;' . $loops;
		} else {
			return "";
		}
	}

        static public function samdivPages($pageNumber, $page, $thisfile) {
		if ($pageNumber > 0) {
			$pre = $page - 1;
			$next = $page + 1;
			$ye=0;
			$loop='';
			$firstAndLast='';
			$nextAndLast='';

			if(strpos($thisfile,'?')){

				$thisfile=$thisfile.'&';

			}else{

				$thisfile=$thisfile.'?';

			}

				$firstAndLast = "<span><a>Club's directory</a></span> 
				<span><a href='" . $thisfile . "page=" . $pre . "' title='previous page'>previous page</a></span>";
				$nextAndLast = "<span><a href='" . $thisfile . "page=" . $next . "' title='next page'> next page</a>";

                        for($i = 1; $i <= $pageNumber; $i ++) {
				if ($page == ($i)) {
					$loop .= "<option value=\"$i\" selected=\"selected\">$i</option>";
				} else {
					$loop .= "<option value=\"$i\">$i</option>";
				}
			}

                        if($loop) $loop="<span><select name=\"page\" onchange=\"document.getElementById('selectbox').submit();\">".$loop."</select></span>";


			return "<div style='clear: both'></div><div class='pageBar'><form id=\"selectbox\" action=\"$thisfile\" method=\"post\">".$firstAndLast . $nextAndLast . $loop."</form></div>";
		} else {
			return "";
		}
	}
	
	static public function categoryPages($pageNumber, $page, $thisfile, $productName) {
		if ($pageNumber > 0) {
			$pre = $page - 1;
			$next = $page + 1;
			$ye=0;
			$loop='';
			$firstAndLast='';
			$nextAndLast='';
			$firstAndLast = "<span><a>Club's directory</a></span>";
			if ($page != 1) {
				$firstAndLast .= "<span><a href='" . $thisfile . "-" . $pre . "-" . $productName . ".html' title='previous page'> previous page</a></span>";
			}
			if ($page != $pageNumber) {
				$nextAndLast = "<span><a href='" . $thisfile . "-" . $next . "-" . $productName . ".html' title='next page'> next page</a>";
			}
                        for($i = 1; $i <= $pageNumber; $i ++) {
				if ($page == ($i)) {
					$loop .= "<option value=\"$i\" selected=\"selected\">$i</option>";
				} else {
					$loop .= "<option value=\"$i\">$i</option>";
				}
			}

                        if($loop) $loop="<span><select name=\"page\" onchange=\"changePage(this);\">".$loop."</select></span>";


			return "<div style='clear: both'></div><div class='pageBar'><form id=\"selectbox\" action=\"$thisfile\" method=\"post\">".$firstAndLast . $nextAndLast . $loop."</form></div>";
		} else {
			return "";
		}
	}

	static public function commonDivAjax($pageNumber, $page, $function) {
		$args = func_get_args ();
		array_shift ( $args );
		array_shift ( $args );
		array_shift ( $args );
		$argString = join ( "','", $args );
		$argString = "'" . $argString . "'";
		
		if ($pageNumber > 0) {
			$pre = $page - 1;
			$next = $page + 1;
			$ye=0;
			$loop='';
			$firstAndLast='';
			$nextAndLast='';
			if ($page > 6) {
				if ($page + 1 <= $pageNumber) {
					if($pageNumber-$page>2){									
						$ye = $page - 7+3;	
					}else{
						$ye = $page - 7 + 1;
					}
				} else {
					$ye = $page - 7;
				}
			}
			if ($pre > 0) {
				
				$firstAndLast = "<a class='pageStyle' href=\"javascript:" . $function . "('1'," . $argString . ");\" title='prev'>&lt;&lt;</a> 
				<a class='pageStyle' href=\"javascript:" . $function . "('" . $pre . "'," . $argString . ");\" title='next'>&lt;</a>";
			
			}
			for($i = $ye; $i < $ye + 7; $i ++) {
				if ($page == ($i + 1)) {
					$loop .= "<a class='pageStyle' id='currentPage' href=\"javascript:" . $function . "('" . ($i + 1) . "'," . $argString . ");\">" . ($i + 1) . "</a> ";
				} else {
					$loop .= "<a class='pageStyle' href=\"javascript:" . $function . "('" . ($i + 1) . "'," . $argString . ");\">" . ($i + 1) . "</a> ";
				}
				if ($i == ($pageNumber - 1)) {
					break;
				}
			}
			
			if ($next <= $pageNumber) {
				
				$nextAndLast = "<a class='pageStyle' href=\"javascript:" . $function . "('" . $next . "'," . $argString . ");\" title='next'>&gt;</a> 
				<a class='pageStyle' href=\"javascript:" . $function . "('" . $pageNumber . "'," . $argString . ");\" title='last'>&gt;&gt;</a>";
			
			}
			
			$urlArray=explode('/',CURRENT_URL);
		
			$urlArray=explode('-',array_pop($urlArray));
			
			if($urlArray[0]=='buyer'||$urlArray[0]=='adminb'){
				
				$alert='To';
				
			}else{
				
				$alert='转到';
				
			}			
		
            for($i = 1; $i <= $pageNumber; $i ++) {
				if ($page == ($i)) {
					$loops .= "<option value=\"$i\" selected=\"selected\">$i</option>";
				} else {
					$loops .= "<option value=\"$i\">$i</option>";
				}
			}

            if($loops) $loops="<span><select name=\"page\" onchange=\"$function($(this).val(),$argString)\">".$loops."</select></span>";
			return $firstAndLast . ' ' . $loop . ' ' . $nextAndLast. $loops;
		} else {
			return "";
		}
	}
	
	public function divPagesBlog($pageNumber, $page)
	{
		if ($pageNumber > 0) {
			$pre = $page - 1;
			$next = $page + 1;
			$ye=0;
			$loop='';
			$firstAndLast='';
			$nextAndLast='';
			
			if(strpos($thisfile,'?')){
				
				$thisfile=$thisfile;
				
			}else{
				
				$thisfile=$thisfile;
				
			}
			if ($page > 6) {
				if ($page + 1 <= $pageNumber) {
					if($pageNumber-$page>2){									
						$ye = $page - 7+3;	
					}else{
						$ye = $page - 7 + 1;
					}
				} else {
					$ye = $page - 7;
				}
			}
			if ($pre > 0) {
				
				$firstAndLast = "<a class='pageStyle' href='/' title='First'>&lt;&lt;</a> 
				<a class='pageStyle' href='news-" . $pre . "' title='Prev'>&lt;</a>";
			
			}
			for($i = $ye; $i < $ye + 7; $i ++) {
				if ($page == ($i + 1)) {
					$loop .= "<a class='current' id='current' href='news-" . ($i + 1) . "'>" . ($i + 1) . "</a> ";
				} else {
					$loop .= "<a class='pageStyle' href='news-" . ($i + 1) . "'>" . ($i + 1) . "</a> ";
				}
				if ($i == ($pageNumber - 1)) {
					break;
				}
			}
			
			if ($next <= $pageNumber) {
				
				$nextAndLast = "<a class='pageStyle' href='news-" . $next . "' title='Next'>&gt;</a> 
				<a class='pageStyle' href='news-" . $pageNumber . "' title='Last'>&gt;&gt;</a>";
			
			}
			return $firstAndLast . ' ' . $loop . ' ' . $nextAndLast;
		} else {
			return "";
		}
	}	
	
	
	public function divPagesPlayer($pageNumber, $page, $thisfile)
	{
		if ($pageNumber > 0) {
			$pre = $page - 1;
			$next = $page + 1;
			$ye=0;
			$loop='';
			$firstAndLast='';
			$nextAndLast='';
			
			if(strpos($thisfile,'?')){
				
				$thisfile=$thisfile;
				
			}else{
				
				$thisfile=$thisfile;
				
			}
			if ($page > 6) {
				if ($page + 1 <= $pageNumber) {
					if($pageNumber-$page>2){									
						$ye = $page - 7+3;	
					}else{
						$ye = $page - 7 + 1;
					}
				} else {
					$ye = $page - 7;
				}
			}
			if ($pre > 0) {
				
				$firstAndLast = "<a class='pageStyle' href='" . $thisfile . "' title='First'>&lt;&lt;</a> 
				<a class='pageStyle' href='" . $thisfile . "_" . $pre . "' title='Prev'>&lt;</a>";
			
			}
			for($i = $ye; $i < $ye + 7; $i ++) {
				if ($page == ($i + 1)) {
					$loop .= "<a class='current' id='current' href='" . $thisfile . "_" . ($i + 1) . "'>" . ($i + 1) . "</a> ";
				} else {
					$loop .= "<a class='pageStyle' href='" . $thisfile . "_" . ($i + 1) . "'>" . ($i + 1) . "</a> ";
				}
				if ($i == ($pageNumber - 1)) {
					break;
				}
			}
			
			if ($next <= $pageNumber) {
				
				$nextAndLast = "<a class='pageStyle' href='" . $thisfile . "_" . $next . "' title='Next'>&gt;</a> 
				<a class='pageStyle' href='" . $thisfile . "_" . $pageNumber . "' title='Last'>&gt;&gt;</a>";
			
			}
			return $firstAndLast . ' ' . $loop . ' ' . $nextAndLast;
		} else {
			return "";
		}
	}	
	
}